package com.lancoo.ccas53.util;

import cn.hutool.http.HttpStatus;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;


@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(description = "返回数据值")
public class ResponseObject<T> implements Serializable {


    @ApiModelProperty(value = "请求结果状态码，200 表示请求成功，其他详见请求结果状态说明")
    private Integer StatusCode;

    @ApiModelProperty(value = "请求不成功时的错误码")
    private Integer ErrCode;

    @ApiModelProperty(value = "异常提示信息")
    private String Msg;

    @ApiModelProperty(value = "具体返回值信息")
    private T Data;

    public static <T> ResponseObject<T> ofSuccess() {
        ResponseObject<T> result = new ResponseObject<T>();
        result.StatusCode = HttpStatus.HTTP_OK;
        result.ErrCode = EnumResultCode.SUCCESS.getCode();
        result.Msg = EnumResultCode.SUCCESS.getResultMsg();
        return result;
    }

    public static <T> ResponseObject<T> ofSuccess(Integer code, String msg) {
        ResponseObject<T> result = new ResponseObject<T>();
        result.StatusCode = HttpStatus.HTTP_OK;
        result.ErrCode = code;
        result.Msg = msg;
        return result;
    }

    public static <T> ResponseObject<T> ofSuccess(Integer code, String msg, T data) {
        ResponseObject<T> result = new ResponseObject<T>();
        result.StatusCode = HttpStatus.HTTP_OK;
        result.ErrCode = code;
        result.Msg = msg;
        result.setData(data);
        return result;
    }

    public static <T> ResponseObject<T> ofSuccess(EnumResultCode resultCode) {
        ResponseObject<T> result = new ResponseObject<T>();
        result.StatusCode = HttpStatus.HTTP_OK;
        result.ErrCode = resultCode.getCode();
        result.Msg = resultCode.getResultMsg();
        return result;
    }

    public static <T> ResponseObject<T> ofSuccess(T data) {
        ResponseObject<T> result = new ResponseObject<T>();
        result.StatusCode = HttpStatus.HTTP_OK;
        result.ErrCode = EnumResultCode.SUCCESS.getCode();
        result.Msg = EnumResultCode.SUCCESS.getResultMsg();
        result.setData(data);
        return result;
    }

    public static <T> ResponseObject<T> ofFail(String msg) {
        ResponseObject<T> result = new ResponseObject<T>();
        result.StatusCode = HttpStatus.HTTP_INTERNAL_ERROR;
        result.ErrCode = EnumResultCode.FAIL.getCode();
        result.Msg = msg;
        return result;
    }

    public static <T> ResponseObject<T> ofFail(Integer code, String msg) {
        ResponseObject<T> result = new ResponseObject<T>();
        result.StatusCode = HttpStatus.HTTP_INTERNAL_ERROR;
        result.ErrCode = code;
        result.Msg = msg;
        return result;
    }

    public static <T> ResponseObject<T> ofFail(Integer code, String msg, T data) {
        ResponseObject<T> result = new ResponseObject<T>();
        result.StatusCode = HttpStatus.HTTP_INTERNAL_ERROR;
        result.ErrCode = code;
        result.Msg = msg;
        result.setData(data);
        return result;
    }

    public static <T> ResponseObject<T> ofFail(EnumResultCode resultEnum) {
        ResponseObject<T> result = new ResponseObject<T>();
        result.StatusCode = HttpStatus.HTTP_INTERNAL_ERROR;
        result.ErrCode = resultEnum.getCode();
        result.Msg = resultEnum.getResultMsg();
        return result;
    }

    public static <T> ResponseObject<T> ofFail(Integer state, Integer code, String msg, T data) {
        ResponseObject<T> result = new ResponseObject<T>();
        result.StatusCode = state;
        result.ErrCode = code;
        result.Msg = msg;
        result.Data = data;
        return result;
    }

    public static <T> ResponseObject<T> ofFail(EnumResultCode resultEnum, T data) {
        ResponseObject<T> result = new ResponseObject<T>();
        result.StatusCode = HttpStatus.HTTP_INTERNAL_ERROR;
        result.ErrCode = resultEnum.getCode();
        result.Msg = resultEnum.getResultMsg();
        result.Data = data;
        return result;
    }

}
